$(function(){
	
	//构建医院选择对话框列表
	$("#gridHospital").datagrid({
		height: 'auto',
	    method: 'get',
	    loadMsg: "数据加载中...",
	    pagination:true,
	    pageSize: 8,
	    pageList:[8,20,30],
	    striped: true,
	    singleSelect:true
	});

	//构建角色列表
	$("#gridQuestionOptions").datagrid({
	    height: 'auto',
	    url: "../questionnaire/question/list?random="+Math.random(),
	    method: 'get',
	    loadMsg: "数据加载中...",
	    pagination:true,
	    pageSize: 8,//每页显示的记录条数，默认为10
	    pageList:[8,20,30],//每页显示几条记录
	    striped: true,
	    singleSelect:true,
	    toolbar:"#tbQuestions"
	});
	
	//构建医院选择列表
	$("#gridQuestionnaireHospital").datagrid({
		height: 'auto',
	    method: 'get',
	    loadMsg: "数据加载中...",
	    striped: true,
	    singleSelect:true,
	    toolbar:"#tbQuestionsHospital"
	});
	
	//如果问卷ID不为空，加载问卷问题
	var questionniareId=$("#txtAddQuestionnaireId").val();
	if((null!=questionniareId)&&(questionniareId!=''))
	{
		$("#gridQuestionOptions").datagrid("load",{
			data:{random:function(){return Math.random();}},
			questionnaireId:questionniareId
		});
		
		$("#gridQuestionnaireHospital").datagrid({
			 url: "../questionnaire/hospital/list?questionnaireId="+questionniareId,
		});
	}
});	

/**
 * 保存问卷
 */
function saveQuestionnaire()
{
	var questionniareId=$("#txtAddQuestionnaireId").val();
	var url="../questionnaire/edit";
	if(null==questionniareId||questionniareId=="")
	{
		url= "../questionnaire/add";
	}
	else
	{
		url="../questionnaire/edit";
	}
	editQuestionnaire(url);
}

/**
 * 修改问卷
 */
function editQuestionnaire(url)
{
	$('#frmQuestionnaireAdd').form('submit',{  
        url:url,  
        onSubmit:function(){
            return $(this).form('validate');
        },  
        success:function(jsonstr){
        	var data=JSON.parse(jsonstr); 
        	if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{data:{random:function(){return Math.random();}}});
				$.messager.alert("提示",data.msg);
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
        },
        error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
    }); 
}

/**
 * 发布问卷
 */
function publishQuestionnaire()
{
	alert("保存并发布问卷");
}

/**
 * 构建操作列
 * val: the field value，也就是field:'id'。
 * row: the row record data。就是这一行的Json数据，包括你已经选择在Datagrid上显示的内容，和没显示的内容。
 * index:索引号
 */
function optColumn(val,row,index)
{
	var optStr="";
	optStr+="<a href='javascript:void(0)' onclick='javascript:delQuestionnaireQuestion("+val+")' style='color:blue'><u>删除</u></a>";
	optStr+="&nbsp;&nbsp;";
	optStr+="<a href='javascript:void(0)' onclick='javascript:editQuestion("+val+","+row.type+",\""+row.description+"\")' style='color:blue'><u>编辑</u></a>";
	return optStr;
}

/**
 * 构建选择医院列表操作列
 * @param val
 * @param row
 * @param index
 */
function optHospitalColumn(val,row,index)
{
	var optStr="";
	optStr+="<a href='javascript:void(0)' onclick='javascript:delQuestionnaireHospital("+val+",\""+row.hospitalName+"\")' style='color:blue'><u>删除</u></a>";
	return optStr;
}

/**
 * 构建类型列
 * 
 * @param val
 * @param row
 * @param index
 */
function typeColumn(val,row,index)
{
	var typeName="";
	val=Number(val);
	switch(val)
	{
	case 1 :
		typeName="单选";
		break;
	case 2 :
		typeName="多选";
		break;
	case 3 :
		typeName="问答";
		break;
	case 4 :
		typeName="自定义模板"
		break;
	}
	return typeName;
}

/**
 * 是否上传文件
 * 
 * 0：需要
1：不需要
 * @param val
 * @param row
 * @param index
 */
function upColumn(val,row,index)
{
	var upName="";
	val=Number(val);
	switch(val)
	{
	case 0 :
		upName="是";
		break;
	case 1 :
		upName="否";
		break;
	}
	return upName;
}

/**
 * 打开编辑问题对话窗口
 */
function openWinQuestion()
{
	var title=$('#txtAddTitle').textbox('getValue');
	if(null==title||title=="")
	{
		$.messager.alert("提示","请先填写问卷标题");
	}
	else
	{
		$("#frmQuestionSingleSelect").form("clear");
		$("#frmQuestionMultiSelect").form("clear");
		$("#frmQuestionInterlocution").form("clear");
		$("#OpTypeSingle").val("add");
		$("#OpTypeMulti").val("add");
		$("#OpTypeInterlocution").val("add");
		$('#winQuestion').window('open');
	}
}

/**
 * 保存单选题
 */
function saveQuestionSingleSelect()
{
	var questionniareId=$("#txtAddQuestionnaireId").val();
	var opTypeSingle=$("#OpTypeSingle").val();
	
	//如果问卷还未保存，就先保存问卷
	if(null==questionniareId||questionniareId=="")
	{
		var title=$('#txtAddTitle').textbox('getValue');
		var description=$('#txtAddDescription').textbox('getValue');
		
		$.ajax({
			type: "get",
			url: "../questionnaire/add",
			data:{
				title:title,
				description:description
			},
			success: function(data){
				if(data.result==true)
				{
					$("#txtAddQuestionnaireId").val(data.questionnaireId);
					doSaveQuestionSSel(data.questionnaireId);
				}
				else
	            {
	            	$.messager.alert("提示",data.msg,"error");
	            }
			}
		});
	}
	else
	{
		if("edit"==opTypeSingle)
		{
			doEditQuestionSSel(questionniareId);
		}
		else
		{
			doSaveQuestionSSel(questionniareId);
		}
	}
}


/**
 * 提交单选问题
 */
function doSaveQuestionSSel(questionniareId)
{
	var description=$('#txtQuestionSSelDesc').val();
	var upload=$("input[name='txtUpload']:checked").val();
	
	var questionOptions=new Array();
	$("input[name='txtQuestionSSel']").each(function(i,obj){
		var option=$(obj).val();
		if(null!=option&&option!='')
		{
			questionOptions.push(option);
		}
	});
	var questionOptionsDes=questionOptions.join("@#@");
	
	$.ajax({
		type: "get",
		url: "../questionnaire/question/add",
		data:{
			type:'1',
			description:description,
			upload:upload,
			questionnaireId:questionniareId,
			questionOptionsDes:questionOptionsDes
		},
		success: function(data){
			if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{
					data:{random:function(){return Math.random();}},
					questionnaireId:questionniareId
					});
				$.messager.alert("提示",data.msg);
				
				$("#frmQuestionSingleSelect").form("clear");
				$("#txtUpload_no").prop('checked',true)
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});
}

/**
 * 修改单选问题提交
 * @param questionniareId
 */
function doEditQuestionSSel(questionniareId)
{
	var description=$('#txtQuestionSSelDesc').val();
	var upload=$("input[name='txtUpload']:checked").val();
	var questionId=$("#editQuestionId").val();
	
	var questionOptions=new Array();
	$("input[name='txtQuestionSSel']").each(function(i,obj){
		var option=$(obj).val();
		if(null!=option&&option!='')
		{
			questionOptions.push(option);
		}
	});
	var questionOptionsDes=questionOptions.join("@#@");
	
	$.ajax({
		type: "get",
		url: "../questionnaire/question/edit",
		data:{
			type:'1',
			id:questionId,
			description:description,
			upload:upload,
			questionnaireId:questionniareId,
			questionOptionsDes:questionOptionsDes
		},
		success: function(data){
			if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{
					data:{random:function(){return Math.random();}},
					questionnaireId:questionniareId
					});
				$.messager.alert("提示",data.msg);
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});
}

/**
 * 保存多选题
 */
function saveQuestionMutiSelect()
{
	var questionniareId=$("#txtAddQuestionnaireId").val();
	var opTypeMulti=$("#OpTypeMulti").val();
	
	//如果问卷还未保存，就先保存问卷
	if(null==questionniareId||questionniareId=="")
	{
		var title=$('#txtAddTitle').textbox('getValue');
		var description=$('#txtAddDescription').textbox('getValue');
		
		$.ajax({
			type: "get",
			url: "../questionnaire/add",
			data:{
				title:title,
				description:description
			},
			success: function(data){
				if(data.result==true)
				{
					$("#txtAddQuestionnaireId").val(data.questionnaireId);
					dosaveQuestionMutiSelect(data.questionnaireId);
				}
				else
	            {
	            	$.messager.alert("提示",data.msg,"error");
	            }
			}
		});
	}
	else
	{
		if("edit"==opTypeMulti)
		{
			doEditQuestionMutiSelect(questionniareId);
		}
		else
		{
			dosaveQuestionMutiSelect(questionniareId);
		}
	}
}

//执行多选保存
function dosaveQuestionMutiSelect(questionniareId)
{
	var description=$('#txtQuestionMSelDesc').val();
	var upload=$("input[name='txtMUpload']:checked").val();
	
	var questionOptions=new Array();
	$("input[name='txtQuestionMSel']").each(function(i,obj){
		var option=$(obj).val();
		if(null!=option&&option!='')
		{
			questionOptions.push(option);
		}
	});
	var questionOptionsDes=questionOptions.join("@#@");
	
	$.ajax({
		type: "get",
		url: "../questionnaire/question/add",
		data:{
			type:'2',
			description:description,
			upload:upload,
			questionnaireId:questionniareId,
			questionOptionsDes:questionOptionsDes
		},
		success: function(data){
			if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{
					data:{random:function(){return Math.random();}},
					questionnaireId:questionniareId
					});
				$.messager.alert("提示",data.msg);
				
				$("#frmQuestionMultiSelect").form("clear");
				$("#txtMUpload_no").prop('checked',true)
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});
}

//执行多选题修改提交
function doEditQuestionMutiSelect(questionniareId)
{
	var description=$('#txtQuestionMSelDesc').val();
	var upload=$("input[name='txtMUpload']:checked").val();
	var questionId=$("#editQuestionId").val();
	
	var questionOptions=new Array();
	$("input[name='txtQuestionMSel']").each(function(i,obj){
		var option=$(obj).val();
		if(null!=option&&option!='')
		{
			questionOptions.push(option);
		}
	});
	var questionOptionsDes=questionOptions.join("@#@");
	
	$.ajax({
		type: "get",
		url: "../questionnaire/question/edit",
		data:{
			type:'2',
			id:questionId,
			description:description,
			upload:upload,
			questionnaireId:questionniareId,
			questionOptionsDes:questionOptionsDes
		},
		success: function(data){
			if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{
					data:{random:function(){return Math.random();}},
					questionnaireId:questionniareId
					});
				$.messager.alert("提示",data.msg);
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});
}

/**
 * 保存问答题
 */
function saveQuestionInterlocution()
{
	var questionniareId=$("#txtAddQuestionnaireId").val();
	var opTypeInterlocution=$("#OpTypeInterlocution").val();
	
	//如果问卷还未保存，就先保存问卷
	if(null==questionniareId||questionniareId=="")
	{
		var title=$('#txtAddTitle').textbox('getValue');
		var description=$('#txtAddDescription').textbox('getValue');
		
		$.ajax({
			type: "get",
			url: "../questionnaire/add",
			data:{
				title:title,
				description:description
			},
			success: function(data){
				if(data.result==true)
				{
					$("#txtAddQuestionnaireId").val(data.questionnaireId);
					doSaveQuestionInterlocution(data.questionnaireId);
				}
				else
	            {
	            	$.messager.alert("提示",data.msg,"error");
	            }
			}
		});
	}
	else
	{
		if("edit"==opTypeInterlocution)
		{
			doEditQuestionInterlocution(questionniareId);
		}
		else
		{
			doSaveQuestionInterlocution(questionniareId);
		}
	}
}

/**
 * 执行问答题保存
 */
function doSaveQuestionInterlocution(questionniareId)
{
	var description=$('#txtQuestionIDesc').val();
	var upload=$("input[name='txtIUpload']:checked").val();
	
	$.ajax({
		type: "get",
		url: "../questionnaire/question/add",
		data:{
			type:'3',
			description:description,
			upload:upload,
			questionnaireId:questionniareId
		},
		success: function(data){
			if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{
					data:{random:function(){return Math.random();}},
					questionnaireId:questionniareId
					});
				$.messager.alert("提示",data.msg);
				
				$("#frmQuestionInterlocution").form("clear");
				$("#txtIUpload_no").prop('checked',true)
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});
}

/**
 * 执行问答题修改保存
 */
function doEditQuestionInterlocution(questionniareId)
{
	var description=$('#txtQuestionIDesc').val();
	var upload=$("input[name='txtIUpload']:checked").val();
	var questionId=$("#editQuestionId").val();
	
	$.ajax({
		type: "get",
		url: "../questionnaire/question/edit",
		data:{
			type:'3',
			id:questionId,
			description:description,
			upload:upload,
			questionnaireId:questionniareId
		},
		success: function(data){
			if(data.result==true)
			{
				$("#gridQuestionOptions").datagrid("load",{
					data:{random:function(){return Math.random();}},
					questionnaireId:questionniareId
					});
				$.messager.alert("提示",data.msg);
			}
			else
            {
            	$.messager.alert("提示",data.msg,"error");
            }
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});
}

/**
 * 预览问卷
 */
function viewQuestionnaire()
{
	var questionniareId=$("#txtAddQuestionnaireId").val();
	if(null==questionniareId||questionniareId=="")
	{
		$.messager.alert("提示","请先保存问卷");
	}
	else
	{
		window.location.href="../weixin/qusetionnaire/goto?questionnaireId="+questionniareId+"&back=true";
	}
}

/**
 * 删除问卷关联的医院
 * @param questionnaireHospitalId
 * @param hospitalName 
 */
function delQuestionnaireHospital(questionnaireHospitalId,hospitalName)
{
	$.messager.confirm('提示','确认删除医院【'+hospitalName+'】么？',function(r){    
	    if (r){    
	    	
	    	$.ajax({
	    		type: "get",
	    		url: "../questionnaire/hospital/del",
	    		data:{
	    			id:questionnaireHospitalId
	    		},
	    		success: function(data){
	    			if(data.result==true)
	    			{
	    				var questionnaireId=$("#txtAddQuestionnaireId").val();
	    				$("#gridQuestionnaireHospital").datagrid({
	    					 url: "../questionnaire/hospital/list?questionnaireId="+questionnaireId,
	    				});
	    				$.messager.alert("提示",data.msg);
	    			}
	    			else
	                {
	                	$.messager.alert("提示",data.msg,"error");
	                }
	    		},
	    		error:function(err){
	    			$.messager.alert("提示",err.responseText,null,function(){
	    				window.location.href="../login/toLogin";
	    			});
	    		}
	    	});   
	    }    
	});  
}

/**
 * 删除问卷问题
 * @param questionId 问题ID
 */
function delQuestionnaireQuestion(questionId)
{
	$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
	    if (r){    
	    	
	    	var questionniareId=$("#txtAddQuestionnaireId").val();
	    	
	    	$.ajax({
	    		type: "get",
	    		url: "../questionnaire/question/del",
	    		data:{
	    			questionnaireId:questionniareId,
	    			questionId:questionId
	    		},
	    		success: function(data){
	    			if(data.result==true)
	    			{
	    				$("#gridQuestionOptions").datagrid("load",{
	    					data:{random:function(){return Math.random();}},
	    					questionnaireId:questionniareId
	    					});
	    				$.messager.alert("提示",data.msg);
	    			}
	    			else
	                {
	                	$.messager.alert("提示",data.msg,"error");
	                }
	    		},
	    		error:function(err){
	    			$.messager.alert("提示",err.responseText,null,function(){
	    				window.location.href="../login/toLogin";
	    			});
	    		}
	    	});   
	    }    
	});  
}

/**
 * 添加单选选择项
 * @param  optionId 问题选项ID
 * @param  description 问题选项描述
 */
var questionSsel=4;
function addQuestionSSel(optionId,description)
{
	var strSSel="";
	++questionSsel;
	if(undefined==description)
	{
		description="";
	}
	strSSel+="<div class='divsslAppend' id='divssl"+questionSsel+"' style='margin-top: 5px;'>";
	strSSel+="<input id='txtQuestionSSel"+optionId+"' name='txtQuestionSSel' class='easyui-textbox'  style='width:300px' value='"+description+"'>";
	strSSel+="&nbsp;<span style='color: red;font-size: 20px;cursor: pointer;padding-left: 4px;' onclick='delQuestionSSel("+questionSsel+")'>×</span>";
	strSSel+="</div>";
	
	$("#tdQuestionSingleSelectOption").append(strSSel);
	$.parser.parse('#tdQuestionSingleSelectOption');
}

/**
 * 删除单选选择项
 */
function delQuestionSSel(delSsel)
{
	$("#divssl"+delSsel).remove();
}


/**
 * 添加多选问题问题选项
 * @param optionId 问题选项ID
 * @param description 问题选项描述
 */
var questionMSel=4;
function addQuestionMSel(optionId,description)
{
	var strMSel="";
	++questionMSel;
	if(undefined==description)
	{
		description="";
	}
	strMSel+="<div class='divMselAppend' id='divMsel"+questionMSel+"' style='margin-top: 5px;'>";
	strMSel+="<input id='txtQuestionMSel"+optionId+"' name='txtQuestionMSel' class='easyui-textbox'  style='width:300px'>";
	strMSel+="&nbsp;<span style='color: red;font-size: 20px;cursor: pointer;padding-left: 4px;' onclick='delQuestionMSel("+questionMSel+")'>×</span>";
	strMSel+="</div>";
	
	$("#tdQuestionMultiSelectOption").append(strMSel);
	$.parser.parse('#tdQuestionMultiSelectOption');
}

/**
 * 删除多选
 */
function delQuestionMSel(delMSel)
{
	$("#divMsel"+delMSel).remove();
}


/**
 * 编辑问题
 * @param questionId 问题ID
 * @param questionType 问题类型
 * @param questionDesc 问题描述
 */
function editQuestion(questionId,questionType,questionDesc)
{
	$.ajax({
		type: "get",
		url: "../questionnaire/question/option/list",
		data:{
			questionId:questionId
		},
		success: function(data){
			var options=data;
			$("#winQuestion").window("open");
			$("#editQuestionId").val(questionId);
			
			if(questionType=='1')
			{
				$('#tabquestion').tabs('select','单选');
				$("#txtQuestionSSelDesc").textbox("setValue",questionDesc);
				$("#txtQuestionSSelDesc").attr("title",questionId);
				$("#OpTypeSingle").val("edit");
				$(".divsslAppend").remove();
				for(var m=0;m<4;m++)
				{
					$("#txtQuestionSSel"+m).textbox("setValue","");
				}
			}
			else if(questionType=='2')
 			{
				$('#tabquestion').tabs('select','多选');
				$("#txtQuestionMSelDesc").textbox("setValue",questionDesc);
				$("#txtQuestionMSelDesc").attr("title",questionId);
				$("#OpTypeMulti").val("edit");
				$(".divMselAppend").remove();
				
				for(var m=0;m<4;m++)
				{
					$("#txtQuestionMSel"+n).textbox("setValue","");
				}
			}
			else if(questionType=='3')
			{
				$('#tabquestion').tabs('select','问答');
				$("#txtQuestionIDesc").textbox("setValue",questionDesc);
				$("#txtQuestionIDesc").attr("title",questionId);
				$("#OpTypeInterlocution").val("edit");
			}
			
			for(var n=0;n<options.length;n++)
			{
				var option=options[n];
				if(questionType=='1')//单选
				{
					if(n<4)
					{
						$("#txtQuestionSSel"+n).textbox("setValue",option.description);
						$("#txtQuestionSSel"+n).attr("title",option.id);
					}
					else
					{
						addQuestionSSel(option.id,option.description);
					}	
				}
				else if(questionType=='2')//多选
				{
					if(n<4)
					{
						$("#txtQuestionMSel"+n).textbox("setValue",option.description);
						$("#txtQuestionSSel"+n).attr("title",option.id);
					}
					else
					{
						addQuestionMSel(option.id,option.description);
					}	
				}
			}
		},
		error:function(err){
			$.messager.alert("提示",err.responseText,null,function(){
				window.location.href="../login/toLogin";
			});
		}
	});   
}

/**
 * 返回问卷列表
 */
function goback()
{
	window.location.href="/pac/questionnaire/gotoPage?pageName=questionnaireList";
}

/**
 * 构建选择医院列
 * @param val
 * @param row
 * @param index
 */
function checkColumn(val,row,index)
{
	var checkStr="";
	checkStr="<input type='checkbox' name='checkHospital' value='"+val+"' onclick='clickCheckMem(\""+val+"\",\""+row.name+"\")'>";
	return checkStr;
}

/**
 * 点击选择医院
 * @param hospitalId 医院ID
 * @param name 医院名称
 */
function clickCheckMem(hospitalId,name)
{
	var checkedMemStr="";
	checkedMemStr+="<span id='spanCheckedMem"+hospitalId+"' name='spanCheckedMem' title='"+hospitalId+"' class='btnSpan'>";
	checkedMemStr+="<i class='close' onclick='removeMem(\"spanCheckedMem"+hospitalId+"\")'>x</i>";
	checkedMemStr+=name;
	checkedMemStr+="</span>";	
	$("#divCheckedMember").append(checkedMemStr);
}

/**
 * 移除成员
 * @param spanMenId：成员面板ID
 */
function removeMem(spanMenId)
{
	$("#"+spanMenId).remove();
}


/**
 * 打开选择医院对话框
 */
function openWinHospitalSel()
{
	$("#gridHospital").datagrid({
		url: "../hospital/listData?random="+Math.random()
	});
	
	$("#divCheckedMember").html("");
	var rows = $("#gridQuestionnaireHospital").datagrid("getRows"); 
	for(var i=0;i<rows.length;i++)
	{
		var hospital=rows[i];
		clickCheckMem(hospital.hospitalId,hospital.hospitalName);
	}
	
	$("#dlgQuestionnaireHospital").window("open");
}

/**
 * 取消选择
 */
function dlgWinHospitalCancel()
{
	$("#dlgQuestionnaireHospital").window("close");
}

/**
 * 确认选择医生
 */
function checkMember()
{
	var questionnaireId=$("#txtAddQuestionnaireId").val();
	
	if(questionnaireId=="")
	{
		$.messager.alert("提示","请先保存问卷","waring");
	}
	else
	{
		var hospitalIdList = new Array(); 
		var checkedDoctorIds="";
		$("span[name='spanCheckedMem']").each(function(){
			var hospitalId=$(this).attr("title");
			hospitalIdList.push(hospitalId);
		});
		
		checkedHospitalIds=hospitalIdList.join(",");
		$.ajax({
			type: "get",
			url:  "../questionnaire/hospital/check",
			data:{
				questionnaireId:questionnaireId,
				memberIds:checkedHospitalIds
			},
			success: function(data){
				if(data.result==true)
	            {
					$("#gridQuestionnaireHospital").datagrid({
						 url: "../questionnaire/hospital/list?questionnaireId="+questionnaireId,
					});
	            	$.messager.alert("提示",data.msg);
	            }
	            else
	            {
	            	$.messager.alert("提示",data.msg,"error");
	            }
			},
			error:function(err){
				$.messager.alert("提示",err.responseText,null,function(){
					window.location.href="../login/toLogin";
				});
			}
		});
	}
}

/**
 * 改变选择
 * @param record
 */
function autoSendSel(record)
{
	if(record.value==1)
	{
		$("#trAutoSendYes").show();
	}
	else
	{
		$("#trAutoSendYes").hide();
	}
}
